package com.shop2cn.app.liveseller.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.app.liveseller.parameter.*;
import com.shop2cn.app.liveseller.service.*;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import org.apache.http.client.ClientProtocolException;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
*云通讯回事件处理
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_TimNotify{
	private static TimNotifyBean timnotifyBean;
	private static TimNotifyCall timnotifyCall;
	private static TimNotifyReq timNotifyReq;
	private static int sellerId ;
	private static String token ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("云通讯回事件处理");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		timnotifyBean=new TimNotifyBean();
		timNotifyReq=new TimNotifyReq();
		initTimNotifyReq();
//		timnotifyCall=new TimNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("api/TimNotify");
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void initTimNotifyReq(){
		timNotifyReq.setCallbackCommand("State.StateChange");
		timNotifyReq.setClientIP(TestDataManager.getRandomIp());
		timNotifyReq.setOptPlatform("Web");
		timNotifyReq.setSdkAppid(LiveRoomShop2cnCallService.ImSdkAppId);
		timNotifyReq.setTimNotifyType("StateChange");
		timNotifyReq.setContenttype("json");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_001() {
		Logger.start(true,"云通讯回事件处理成功,用户上线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomShop2cnWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_002() {
		Logger.start(true,"云通讯回事件处理成功,用户下线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			Info.setTo_Account("345");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
			UserOnlineStatus uo = new LiveRoomShop2cnWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_003() {
		Logger.start(true,"云通讯回事件处理成功,用户更改在线状态");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomShop2cnWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			
			timNotifyReq.setClientIP(TestDataManager.getRandomIp());
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			uo = new LiveRoomShop2cnWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_004() {
		Logger.start(true,"未传用户id.云通讯回事件处理失败");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
//			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("FAIL", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("1", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_005() {
		Logger.start(true,"sdkAppid错误.云通讯回事件处理失败");
		try {
			timNotifyReq.setSdkAppid("123");
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("FAIL", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("1", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_006() {
		Logger.start(true,"callbackCommand不是待处理事件,不处理");
		try {
			timNotifyReq.setCallbackCommand("err");
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("err");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("FAIL", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("1", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_007() {
		Logger.start(true,"云通讯回事件处理成功,global用户上线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("global-123");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomShop2cnWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_008() {
		Logger.start(true,"云通讯回事件处理成功,global用户下线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			Info.setTo_Account("global-345");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
			UserOnlineStatus uo = new LiveRoomShop2cnWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_009() {
		Logger.start(true,"云通讯回事件处理成功,global用户更改在线状态");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Login");
			Info.setReason("Register");
			Info.setTo_Account("global-1234");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			UserOnlineStatus uo = new LiveRoomShop2cnWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线
			Logger.verifyEquals(1, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			
			timNotifyReq.setClientIP(TestDataManager.getRandomIp());
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			Info.setAction("Logout");
			Info.setReason("TimeOut");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			uo = new LiveRoomShop2cnWapper().selectGlobalUserOnlineStatus(Info.getTo_Account().substring(7));
			Logger.verifyEquals(0, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	api/TimNotify?CallbackCommand=Group.CallbackAfterSendMsg&ClientIP=114.80.87.210&OptPlatform=iOS&SdkAppid=1400046801
//			{
//				"CallbackCommand" : "Group.CallbackAfterSendMsg",
//				"From_Account" : "20226434",
//				"GroupId" : "@TGS#aDNQD2RFB",
//				"MsgBody" : [{
//						"MsgContent" : {
//							"Data" : "{\"headPic\":\"http:\\/\\/pic1.ymatou.com\\/G01\\/M00\\/3E\\/6C\\/rBBlD1vFVtiAOtqmAABW6FtzAIo589_1_1_m.jpg\",\"userAction\":1,\"userId\":\"20226434\",\"nickName\":\"zhangyi_buyer001\"}",
//							"Desc" : "",
//							"Ext" : ""
//						},
//						"MsgType" : "TIMCustomElem"
//					}, {
//						"MsgContent" : {
//							"Text" : "{\"msg\":\"Gdhhdh\"}"
//						},
//						"MsgType" : "TIMTextElem"
//					}
//				],
//				"MsgSeq" : 11,
//				"MsgTime" : 1543991688,
//				"Type" : "AVChatRoom"
//			}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_010() {
		Logger.start(true,"云通讯回事件处理成功,用户在group中发消息回调Group.CallbackAfterSendMsg");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			String groupid=createsellerliveBean.getLiveDto().getGroupId();
//			String groupid=LiveRoomShop2cnCallService.CreateGroup("CallbackAfterSendMsg:"+TestDataManager.getRandomNum(5),sellerId);
//			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(createsellerliveBean,sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomShop2cnCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
//			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
//			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
//			Integer uid=urrc.getUserid();
//			String logoimg="http://www.ymatou.com/test2.jpg";
//			JUserCallService.SetUserLogoCall(uid, logoimg);
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			Integer uid = DGUserCallService.UserCreateCall(usercreateBean);
			
			timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
			timNotifyReq.setContenttype(null);
			timNotifyReq.setTimNotifyType(null);
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
			timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
			timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
			timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
			timnotifyBean.setFromAccount(uid.toString());
			timnotifyBean.setGourpId(groupid);
			List<TimChatMessageBody> msgBody=new ArrayList<>();
			//TIMTextElem
			TimChatMessageBody TIMTextElem=new TimChatMessageBody();
			TIMTextElem.setMsgType("TIMTextElem");
			TimChatMessageContent msgContent=new TimChatMessageContent();
			String content="relmsg";
			msgContent.setText("{\"msg\":\""+content+"\"}");
			TIMTextElem.setMsgContent(msgContent);
			msgBody.add(TIMTextElem);
			//TIMTextElem
			TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
			TIMCustomElem.setMsgType("TIMCustomElem");
			TimChatMessageContent cusMsgContent=new TimChatMessageContent();
			cusMsgContent.setData("{\"headPic\":\""+usercreateBean.getLogoUrl()+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+usercreateBean.getLoginId()+"\",\"buyerLevel\":\""+1+"\"}");
			TIMCustomElem.setMsgContent(cusMsgContent);
			msgBody.add(TIMCustomElem);
			
			timnotifyBean.setMsgBody(msgBody);
			timnotifyBean.setType("AVChatRoom");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			//异步 文件缓存
			Thread.sleep(1000);
			List<LiveChatMessagePo> msgs = new LiveRoomShop2cnWapper().selectLivehatMessageByMsgSeq(timnotifyBean.getMsgSeq());
			Logger.verifyEquals(1, msgs.size(), "验证消息数量");
			Logger.debug(FormatUtil.beanToGSONString(msgs.get(0)));
			Logger.verifyEquals(uid, msgs.get(0).getUserId(), "验证uid");
			Logger.verifyEquals(usercreateBean.getLoginId(), msgs.get(0).getNickName(), "验证nickName");
			Logger.verifyEquals(1, msgs.get(0).getMsgType(), "验证msgType");
			Logger.verifyEquals(content, msgs.get(0).getMsgContent(), "验证msgContent");
			Logger.verifyEquals(timnotifyBean.getMsgTimestamp(), msgs.get(0).getMsgTime().getTime()/1000, "验证getMsgTime");
			Logger.verifyEquals(1, msgs.get(0).getBuyerLevel(), "验证BuyerLevel");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_011() {
		Logger.start(true,"云通讯回事件处理成功,用户在group中发消息回调Group.CallbackAfterSendMsg-新增crown皇冠标示");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			String groupid=createsellerliveBean.getLiveDto().getGroupId();
//			String groupid=LiveRoomShop2cnCallService.CreateGroup("CallbackAfterSendMsg:"+TestDataManager.getRandomNum(5),sellerId);
//			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(createsellerliveBean,sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomShop2cnCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			Integer uid = DGUserCallService.UserCreateCall(usercreateBean);
			
			timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
			timNotifyReq.setContenttype(null);
			timNotifyReq.setTimNotifyType(null);
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
			timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
			timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
			timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
			timnotifyBean.setFromAccount(uid.toString());
			timnotifyBean.setGourpId(groupid);
			List<TimChatMessageBody> msgBody=new ArrayList<>();
			//TIMTextElem
			TimChatMessageBody TIMTextElem=new TimChatMessageBody();
			TIMTextElem.setMsgType("TIMTextElem");
			TimChatMessageContent msgContent=new TimChatMessageContent();
			String content="relmsg";
			msgContent.setText("{\"msg\":\""+content+"\"}");
			TIMTextElem.setMsgContent(msgContent);
			msgBody.add(TIMTextElem);
			//TIMTextElem
			TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
			TIMCustomElem.setMsgType("TIMCustomElem");
			TimChatMessageContent cusMsgContent=new TimChatMessageContent();
			cusMsgContent.setData("{\"headPic\":\""+usercreateBean.getLogoUrl()+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+usercreateBean.getLoginId()+"\",\"buyerLevel\":\""+1+"\",\"crown\":\""+1+"\"}");
			TIMCustomElem.setMsgContent(cusMsgContent);
			msgBody.add(TIMCustomElem);
			
			timnotifyBean.setMsgBody(msgBody);
			timnotifyBean.setType("AVChatRoom");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			//异步 文件缓存
			Thread.sleep(1000);
			List<LiveChatMessagePo> msgs = new LiveRoomShop2cnWapper().selectLivehatMessageByMsgSeq(timnotifyBean.getMsgSeq());
			Logger.verifyEquals(1, msgs.size(), "验证消息数量");
			Logger.debug(FormatUtil.beanToGSONString(msgs.get(0)));
			Logger.verifyEquals(uid, msgs.get(0).getUserId(), "验证uid");
			Logger.verifyEquals(usercreateBean.getLoginId(), msgs.get(0).getNickName(), "验证nickName");
			Logger.verifyEquals(1, msgs.get(0).getMsgType(), "验证msgType");
			Logger.verifyEquals(content, msgs.get(0).getMsgContent(), "验证msgContent");
			Logger.verifyEquals(timnotifyBean.getMsgTimestamp(), msgs.get(0).getMsgTime().getTime()/1000, "验证getMsgTime");
			Logger.verifyEquals(1, msgs.get(0).getBuyerLevel(), "验证BuyerLevel");
			Logger.verifyEquals(1, msgs.get(0).getCrown(), "验证Crown");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TimNotify_012() {
		Logger.start(true,"云通讯回事件处理成功,用户在group中发消息回调Group.CallbackAfterSendMsg-新增newComer新人标示");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			String groupid=createsellerliveBean.getLiveDto().getGroupId();
//			String groupid=LiveRoomShop2cnCallService.CreateGroup("CallbackAfterSendMsg:"+TestDataManager.getRandomNum(5),sellerId);
//			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(createsellerliveBean,sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomShop2cnCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			Integer uid = DGUserCallService.UserCreateCall(usercreateBean);
			
			timNotifyReq.setCallbackCommand("Group.CallbackAfterSendMsg");
			timNotifyReq.setContenttype(null);
			timNotifyReq.setTimNotifyType(null);
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			SyncTimMsgCallBackReq timnotifyBean=new SyncTimMsgCallBackReq();
			timnotifyBean.setCallbackCommand("Group.CallbackAfterSendMsg");
			timnotifyBean.setMsgSeq(YMTDateUtil.getDate().getTime());
			timnotifyBean.setMsgTimestamp(YMTDateUtil.getDate().getTime()/1000);
			timnotifyBean.setFromAccount(uid.toString());
			timnotifyBean.setGourpId(groupid);
			List<TimChatMessageBody> msgBody=new ArrayList<>();
			//TIMTextElem
			TimChatMessageBody TIMTextElem=new TimChatMessageBody();
			TIMTextElem.setMsgType("TIMTextElem");
			TimChatMessageContent msgContent=new TimChatMessageContent();
			String content="relmsg";
			msgContent.setText("{\"msg\":\""+content+"\"}");
			TIMTextElem.setMsgContent(msgContent);
			msgBody.add(TIMTextElem);
			//TIMTextElem
			TimChatMessageBody TIMCustomElem=new TimChatMessageBody();
			TIMCustomElem.setMsgType("TIMCustomElem");
			TimChatMessageContent cusMsgContent=new TimChatMessageContent();
			cusMsgContent.setData("{\"headPic\":\""+usercreateBean.getLogoUrl()+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+usercreateBean.getLoginId()+"\",\"buyerLevel\":\""+1+"\",\"newComer\":\""+1+"\"}");
			TIMCustomElem.setMsgContent(cusMsgContent);
			msgBody.add(TIMCustomElem);
			
			timnotifyBean.setMsgBody(msgBody);
			timnotifyBean.setType("AVChatRoom");
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			//异步 文件缓存
			Thread.sleep(1000);
			List<LiveChatMessagePo> msgs = new LiveRoomShop2cnWapper().selectLivehatMessageByMsgSeq(timnotifyBean.getMsgSeq());
			Logger.verifyEquals(1, msgs.size(), "验证消息数量");
			Logger.debug(FormatUtil.beanToGSONString(msgs.get(0)));
			Logger.verifyEquals(uid, msgs.get(0).getUserId(), "验证uid");
			Logger.verifyEquals(usercreateBean.getLoginId(), msgs.get(0).getNickName(), "验证nickName");
			Logger.verifyEquals(1, msgs.get(0).getMsgType(), "验证msgType");
			Logger.verifyEquals(content, msgs.get(0).getMsgContent(), "验证msgContent");
			Logger.verifyEquals(timnotifyBean.getMsgTimestamp(), msgs.get(0).getMsgTime().getTime()/1000, "验证getMsgTime");
			Logger.verifyEquals(1, msgs.get(0).getBuyerLevel(), "验证BuyerLevel");
			Logger.verifyEquals(1, msgs.get(0).getNewComer(), "验证newComer");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TimNotify_013() {
		Logger.start(true,"云通讯回事件处理成功,用户断线");
		try {
			timnotifyCall=new TimNotifyCall(FormatUtil.beanToHttpString(timNotifyReq, true,false));
			timnotifyBean.setCallbackCommand("State.StateChange");
			StateChangeInfo Info=new StateChangeInfo();
			Info.setAction("Disconnect");
			Info.setReason("LinkClose");
			Info.setTo_Account("345");
			timnotifyBean.setInfo(Info);
			timnotifyCall.setData(timnotifyBean);
			timnotifyCall.callService();			
			Logger.verifyEquals("OK", timnotifyCall.getString("ActionStatus"),"验证ActionStatus");
			Logger.verifyEquals("0", timnotifyCall.getString("ErrorCode"),"验证ErrorCode");
			
			UserOnlineStatus uo = new LiveRoomShop2cnWapper().selectUserOnlinestatus(Info.getTo_Account());
			Logger.verifyEquals(timNotifyReq.getClientIP(), uo.getClientIp(),"验证clientip");
			Logger.verifyEquals(timNotifyReq.getOptPlatform(), uo.getPlatForm(),"验证PlatForm");
			//1在线 0下线 2断开
			Logger.verifyEquals(2, uo.getOnlineStatus(),"验证OnlineStatus");
			Logger.verifyEquals(Info.getReason(), uo.getReason(),"验证Reason");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}